package utils;

import java.util.HashMap;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.SimpleDriverDataSource;

public class DataSourceHelper {
	private static HashMap<String, DataSource> map = new HashMap<String, DataSource>();
	
	//should be syncronized
	public synchronized static DataSource getDataSource(String url) {
		DataSource dataSource = (DataSource)map.get(url);
		if( dataSource == null ){
			SimpleDriverDataSource basicDataSource= (SimpleDriverDataSource)SpringBeanProxy.getBean("dataSource");
			basicDataSource.setUrl(url);
			dataSource = (DataSource)basicDataSource;
			map.put(url, dataSource);
		}
		return dataSource;
	}
}
